package main

import (
	"fmt"
	"local/datastructure/queue"
)

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func main() {
}

func preOrder(root *TreeNode) {
	if root == nil {
		return
	}

	fmt.Print(root.Val)
	preOrder(root.Left)
	preOrder(root.Right)
}

func midOrder(root *TreeNode) {
	if root == nil {
		return
	}

	preOrder(root.Left)
	fmt.Print(root.Val)
	preOrder(root.Right)
}

func tailOrder(root *TreeNode) {
	if root == nil {
		return
	}

	tailOrder(root.Left)
	tailOrder(root.Right)
	fmt.Print(root.Val)
}

func levelOrder(root *TreeNode) {
	if root == nil {
		return
	}
	q := queue.NewQueue()
	q.Push(root)
	for !q.IsEmpty() {
		node, _ := q.Pop()
		curr := node.(*TreeNode)
		fmt.Print(curr.Val)
		if curr.Left != nil {
			q.Push(curr.Left)
		}

		if curr.Right != nil {
			q.Push(curr.Right)
		}
	}
}
